#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

vector<string> generateParenthesis(int n) {
    int m = n * 2;
    vector<string> res;
    auto t = string(m, 0);

    auto dfs = [&](auto&& dfs, int i, int l) {
        if (i == m)
        {
            res.push_back(t);
            return;
        }

        if (l < n)
        {
            t[i] = '(';
            dfs(dfs, i + 1, l + 1);
        }
        if (i - l < l)
        {
            t[i] = ')';
            dfs(dfs, i + 1, l);
        }
    };

    dfs(dfs, 0, 0);
    return res;
}

int longestCommonSubsequence(string text1, string text2) {
    int n = text1.size(), m = text2.size();
    vector<vector<int>> f(n + 1, vector<int>(m + 1));

    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
        {
            if (text1[i - 1] == text2[j - 1])
                f[i][j] = f[i - 1][j - 1] + 1;
            else f[i][j] = max(f[i - 1][j], f[i][j - 1]);
        }
    return f[n][m];
}